<div class="layui-col-md12">
    <div class="layui-card">
        <div class="layui-card-header">下单配置</div>
        <div class="layui-card-body">

            <form class="layui-form" action="" lay-filter="orderConfig-from">
                <input type="hidden" name="id"  th:value="${#strings.isEmpty(user)?'':#strings.isEmpty(user.id)?'':user.id}"/>
                <!--  <div class="layui-form">-->
                <div class="layui-form-item">
                    <label class="layui-form-label" for="notifyUrl">地址</label>
                    <div class="layui-input-block">
                        <input type="text" name="notifyUrl" id="notifyUrl" lay-verify="required|url"
                               th:value="${#strings.isEmpty(user)?'':#strings.isEmpty(user.notifyUrl)?'':user.notifyUrl}"
                               class="layui-input"/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" for="returnUrl">地址</label>
                    <div class="layui-input-block">
                        <input type="text" name="returnUrl" id="returnUrl" lay-verify="url"
                               th:value="${#strings.isEmpty(user)?'':#strings.isEmpty(user.returnUrl)?'':user.returnUrl}"
                               class="layui-input"/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" for="proxyIpUrl">地址</label>
                    <div class="layui-input-block">
                        <input type="text" name="proxyIpUrl" id="proxyIpUrl" lay-verify="url"
                               th:value="${#strings.isEmpty(user)?'':#strings.isEmpty(user.proxyIpUrl)?'':user.proxyIpUrl}"
                               class="layui-input"/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" for="enabledProxy">ip代理启用</label>
                    <div class="layui-input-block">
                        <input type="checkbox" th:checked="${#strings.isEmpty(user)?'':#strings.isEmpty(user.enabledProxy)?'false':user.enabledProxy}" id="enabledProxy" name="proxy" lay-skin="switch" lay-text="启用|禁用" lay-filter="enabledProxy">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" type="button" lay-submit lay-filter="set_orderConfig">确认保存</button>
                    </div>
                </div>
                <!-- </div>-->
            </form>
        </div>
    </div>
</div>
<script th:inline="javascript">
    /*<![CDATA[*/

    layui.use(['form'], function () {
        let form = layui.form;

        form.render(); //刷新渲染

        form.on('switch(enabledProxy)', function (data) {
            let status = data.elem.checked ? '启动' : '禁用';
            layer.tips('温馨提示：您已选择' + status + '代理IP,请提交', data.othis);
        });

        //自定义验证规则
        form.verify({
            mobile: function(value){
                if(value.length !== 11){
                    return '手机号必须11位';
                }
                if((!/^[1-9]+[0-9]*]*$/.test(value))){
                    return '手机号必须是数字';
                }
            },
            code: function (value) {
                if(value.length <1){
                    return '验证码不能为空';
                }
            }
        });

        //监听提交
        form.on('submit(set_orderConfig)', function (data) {
            $.ajax({
                type: 'POST',
                contentType: 'application/json;charset=UTF-8',
                url: "/user/save",
                data: JSON.stringify(data.field),
                success: function (result) {
                    if (result.code === 1) {
                        layer.msg('保存成功', {icon: 1, time: 1200});
                        form.val("addPddBuyer-from", {
                            "notifyUrl": data.field.notifyUrl
                        });
                    } else {
                        layer.msg(result.message, {icon: 2, time: 1200});
                    }
                },
                error: function (e) {
                    layer.msg('网络错误', {icon: 2});
                }
            });
        });

    });
    /*]]>*/
</script>